<template>
  <el-dialog
    title="修改"
    :visible.sync="editDialogVisible"
    width="50%"
    @close="editDialogClosed"
  >
    <el-form
      ref="editFormRef"
      :model="editForm"
      label-width="70px"
      :rules="editFormRules"
      hide-required-asterisk
    >
      <el-form-item label="角色名称" prop="roleName">
        <el-input v-model="editForm.roleName"></el-input>
      </el-form-item>
      <el-form-item label="角色描述">
        <el-input v-model="editForm.roleDesc"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="editDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="editRoler">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      editDialogVisible: false,
      editForm: {
      },
      editFormRules: {
        roleName: [
          {
            required: true,
            message: '请输入角色名',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  methods:{
    editDialogClosed() {
      this.$refs.editFormRef.resetFields()
    },
    editRoler() {
        this.$refs.editFormRef.validate(async (valid) => {
        if (!valid) return
        const { data: res } = await this.$http.put(
          'roles/' + this.editForm.roleId,
          {
            roleName: this.editForm.roleName,
            roleDesc: this.editForm.roleDesc,
          }
        )
        if (res.meta.status !== 200) {
          this.$message.error('更新角色失败')
        }
        this.editDialogVisible = false
        this.$emit('getRoleList')
        this.$message.success('更新角色成功！')
      })
    }
  }
}
</script>

<style>
</style>